package com.gitee.secretopen.sso.config;


import com.gitee.secretopen.sso.interceptor.AdminLoginInterceptor;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.HandlerInterceptor;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

/**
 * 　@description: TODO
 * 　@author 陈_C
 * 　@date 2020/3/13 23:37
 *
 */
@Configuration
public class WebMvcConfig implements WebMvcConfigurer {

    @Bean
    public HandlerInterceptor getAdminLoginInterceptor(){
        return new AdminLoginInterceptor();
    }

    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        registry.addInterceptor(getAdminLoginInterceptor()).addPathPatterns("/**")
                //需要配置2：----------- 告知拦截器：/static/admin/** 与 /static/user/** 不需要拦截 （配置的是 路径）
                .excludePathPatterns(
                        "/captchaImage",
                        "/admin/login",
                        "/admin/logout",
                        "/sso/login",
                        "/sso/getUser",
                        "/sso/logout",
                        "/css/**",
                        "/data/**",
                        "/images/**",
                        "/js/**",
                        "/lib/**",
                        "classpath:/static/");

    }



    @Override
    public void addResourceHandlers(ResourceHandlerRegistry registry) {
        registry.addResourceHandler("/**")
                .addResourceLocations("classpath:/static/");


    }




}
